package vno.fux.res.manager
{
	import vno.fux.GlobalVar;
	import vno.fux.res.pool.NpcResource;
	import vno.fux.res.pool.RM_CRM;
	import vno.fux.res.pool.ResourcePool;
	import flash.utils.getQualifiedClassName;
	import vno.fux.res.pool.Resource;

	internal class CharacterResourceManager
	{
		public static var instance:CharacterResourceManager;
		private const obj_id:String = "RM_CRM";
		private var _resourcePool:ResourcePool;
		private var _loaderManager:LoaderManager;
		private var _resInfo:XML;
		/*
		var chares:XML=<characterRes/>;
		chares.appendChild(<playerRes/>);
		chares.appendChild(<npcRes/>)
		chares.playerRes=resourse.characterRes.playerRes;
		chares.npcRes=resourse.characterRes.npcRes;
		return 	chares;
		*/

		public function CharacterResourceManager(pvt:PrivateClass, resInfo_:XML)
		{
			_resourcePool = ResourcePool.getInstance();
			_loaderManager =  ResourceManager.loader;
			_resInfo = resInfo_;
		}
		public function load(id:uint):void
		{
			use namespace RM_CRM;
			//trace(getQualifiedClassName(_chaResInfo..res.(@id==id)[0]));
			for each(var res:XML in _resInfo.assets.(@id==id)[0].elements())
			{
				if(res.name()=="face") continue;
				var url:String = res.@url;
				var chaRes:Resource = _resourcePool.chaRes.getRes(id);
				var mission:ResourceMission = new ResourceMission(GlobalVar.webUrl+url, chaRes["_"+res.name()], CommonLoader.PIC, chaRes, _loaderManager.getId());
				_loaderManager.addMission(mission);
			}
		}
		
		public static function init(resInfo_:XML):void
		{
			if(CharacterResourceManager.instance)
			{
				throw new Error("You can't init the CharacterResourceManager twice!")
			}
			CharacterResourceManager.instance = new CharacterResourceManager(new PrivateClass, resInfo_);
		}
		
		public static function getInstance():CharacterResourceManager
		{
			return CharacterResourceManager.instance;
		}
	}
}
class PrivateClass
{
	public function PrivateClass()
	{
	}
}